﻿using MangoMes.Commont.DBContext;
using MangoMes.Commont.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using System.Data;
using MySql.Data;
using Microsoft.Extensions.Configuration;
using MySql.Data.MySqlClient;
using static Dapper.SqlMapper;

namespace MangoMes.Commont.Infrastructures.Repository
{
    public class BateRepository <T> :IBateRepository<T> where T : class
    {
        
        public async Task<int> Add(string sql, T entity,string conter)
        {
            using (IDbConnection Db=new MySqlConnection(conter))
            {
                var cou =await Db.ExecuteAsync(sql, entity);
                return cou;
            }
        }

        public async Task<int> AddRang(string sql, List<T> entities, string conter)
        {
            using (IDbConnection Db = new MySqlConnection(conter))
            {
                var cou =await Db.ExecuteAsync(sql, entities);
                return cou;
            }
        }
        public  IEnumerable<T> GetAll(string sql, T entity, string conter)
        {
            using (IDbConnection Db = new MySqlConnection(conter))
            {
                var cou =  Db.Query<T>(sql, entity);
                return cou;
            }
        }

        //public async Task<int> Update(string sql, T entity, string conter)
        //{
        //    using (IDbConnection Db = new MySqlConnection(conter))
        //    {
        //        var cou = Db.Execute(sql, entity);
        //        return cou;
        //    }
        //}
        //public async Task<int> Delete(string sql, T entity, string conter)
        //{
        //    using (IDbConnection Db = new MySqlConnection(conter))
        //    {
        //        var cou = Db.Execute(sql, entity);
        //        return cou;
        //    }
        //}
    }
}
